package dimension.starry.player;

import dimension.starry.Tasks.PlayerTaskManager;
import dimension.starry.constants.PlayerDataType;
import dimension.starry.dataManager.PlayerDataManager;
import net.minecraft.server.network.ServerPlayerEntity;

/**
 * @author 150149
 */
public class MagicRecover {

    public static PlayerTaskManager.PlayerTask getMagicRecoverTask() {
        return player -> {
            long magic = PlayerDataManager.getLong(player, PlayerDataType.MAGIC);
            long maxMagic = PlayerDataManager.getLong(player, PlayerDataType.MAX_MAGIC);
            if (magic < maxMagic && player != null) {
                long regenCount = ComputedPlayerInfo.getMagicRegen(player);
                PlayerDataManager.setServerPlayerData(player, PlayerDataType.MAGIC, magic + regenCount);
            }
        };
    }

    public static void onPlayerRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
        long maxMagic = PlayerDataManager.getLong(newPlayer, PlayerDataType.MAX_MAGIC);
        PlayerDataManager.setServerPlayerData(newPlayer, PlayerDataType.MAX_MAGIC, maxMagic);
    }

}
